/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Panel.java
 *
 * Created on 2/07/2011, 01:38:30 AM
 */
package othello;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

/**
 *
 * @author raul
 */
public class Panel extends javax.swing.JPanel {

    /** Creates new form Panel */
    Casilla tablero[][] = new Casilla[8][8];

    public Panel() {
        initComponents();
        dibujar_tablero();

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
    public void dibujar_tablero() {

        this.setLayout(new GridBagLayout());
        GridBagConstraints c = new GridBagConstraints();

        for (int fil = 0; fil < 8; fil++) {

            for (int col = 0; col < 8; col++) {
                Casilla casilla = new Casilla(fil, col);
                casilla.key=(byte)(fil*8+col);

                casilla.setBackground(Color.LIGHT_GRAY);
                tablero[fil][col] = casilla;

                c.fill = GridBagConstraints.HORIZONTAL;
                c.weightx = GridBagConstraints.BOTH;
                c.gridx = col;
                c.gridy = fil;

                this.add(casilla, c);


            }

        }

        this.setMinimumSize(new Dimension(500, 500));
        this.setPreferredSize(new Dimension(500, 500));
        this.setSize(500, 500);

        //seleccionar las primeras 4 fichas
        tablero[3][3].setBackground(Color.BLACK);
        tablero[3][4].setBackground(Color.WHITE);
        tablero[4][3].setBackground(Color.WHITE);
        tablero[4][4].setBackground(Color.BLACK);

    }
}
